package com.hankol.feature_wine_meal.fragment

import android.os.Bundle
import android.view.View
import com.baselibrary.Constants
import com.baselibrary.router.ActivityRouter
import com.baselibrary.utils.ARouterUtils
import com.baselibrary.activity.BaseFragment
import com.hankol.feature_wine_meal.FineFoodActivity
import com.hankol.feature_wine_meal.R
import com.hankol.feature_wine_meal.adapter.EliteRecommendAdapter
import com.hankol.feature_wine_meal.bean.FoodDetailsBean
import com.hankol.feature_wine_meal.databinding.FragmentEliteBinding

class EliteFragment : BaseFragment() {
    private lateinit var mDataBinding: FragmentEliteBinding
    private val adapter by lazy { EliteRecommendAdapter() }
    private var beanList: ArrayList<FoodDetailsBean> = arrayListOf()
    private var recommendId: Long = 0
    private var recommendTitle: String = ""

    companion object {
        const val RECOMMEND_BEAN: String = "RECOMMEND_BEAN"
        const val RECOMMEND_ID: String = "RECOMMEND_ID"
        const val RECOMMEND_TITLE: String = "RECOMMEND_TITLE"

        @JvmStatic
        fun newInstance(beanList: ArrayList<FoodDetailsBean>, recommendId: Long, title: String) = EliteFragment().apply {
            val bundle = Bundle()
            bundle.putParcelableArrayList(RECOMMEND_BEAN, beanList)
            bundle.putLong(RECOMMEND_ID, recommendId)
            bundle.putString(RECOMMEND_TITLE, title)
            arguments = bundle
        }
    }


    override fun getLayoutId(): Int {
        return R.layout.fragment_elite
    }

    override fun init() {
        mDataBinding = getDataBinding<FragmentEliteBinding>()
        initData()
        initListener()
        mDataBinding.tvEliteFoodMore.paint.isFakeBoldText = true
        mDataBinding.rvEliteFood.adapter = adapter
        adapter.setNewData(beanList)

        if (beanList.size >= 7) {
            mDataBinding.mhs.setKickBack(true)
            mDataBinding.llEliteFoodMoreType.visibility = View.VISIBLE
        } else {
            mDataBinding.mhs.setKickBack(false)
            mDataBinding.llEliteFoodMoreType.visibility = View.GONE
        }
    }

    fun initData() {
        arguments?.let {
            recommendId = it.getLong(RECOMMEND_ID)
            recommendTitle = it.getString(RECOMMEND_TITLE, "")
            val list = it.getParcelableArrayList<FoodDetailsBean>(RECOMMEND_BEAN)
            if (!list.isNullOrEmpty()) {
                beanList.clear()
                beanList.addAll(list)
            }
        }
    }

    fun initListener() {

        mDataBinding.mhs.setOnKickBackCallBack {
            val hashMap: HashMap<String, Any> = hashMapOf()
            hashMap[FineFoodActivity.WINE_MEAL_RECOMMEND_INFO_ID] = recommendId
            hashMap[FineFoodActivity.WINE_MEAL_RECOMMEND_INFO_TITLE] = recommendTitle
            ARouterUtils.jump(ActivityRouter.WINE_MEAL.WINE_MEAL_FINE_FOOD, hashMap)
        }

        mDataBinding.llEliteFoodMoreType.setOnClickListener {
            val hashMap: HashMap<String, Any> = hashMapOf()
            hashMap[FineFoodActivity.WINE_MEAL_RECOMMEND_INFO_ID] = recommendId
            hashMap[FineFoodActivity.WINE_MEAL_RECOMMEND_INFO_TITLE] = recommendTitle
            ARouterUtils.jump(ActivityRouter.WINE_MEAL.WINE_MEAL_FINE_FOOD, hashMap)
        }


        adapter.setOnItemClickListener { _, _, position ->
            val hashMap: HashMap<String, Any> = hashMapOf()
            hashMap[Constants.WINE_MEAL_DETAILS_ID] = beanList[position].id
            hashMap["DRINK_FOOD_PLATE_NAME"] = "精选专区"
            hashMap["CLASS_NAME"] = ""
            hashMap["RECOMMEND_NAME"] = "精选推荐"
            ARouterUtils.jump(ActivityRouter.WINE_MEAL.WINE_MEAL_DETAILS, hashMap)
        }
    }

    fun testData() {

    }
}